package com.jf.session.exercise;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:22954
 * Date:2024-08-29
 * Time:2:22
 */
@WebServlet(name = "LoginCheckServlet", urlPatterns = "/loginCheck")
public class LoginCheckServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        if (password != null && password.equals("666666")) {
            HttpSession session = req.getSession();
            session.setAttribute("username", username);
            req.getRequestDispatcher("/manage").forward(req, resp);
        } else {
            String contextPath = req.getContextPath();
            resp.sendRedirect(contextPath + "/error.html");
        }
    }
}
